package com.zcf.controller;

import com.zcf.dto.ArticleDto;
import com.zcf.pojo.Article;
import com.zcf.pojo.PageBean;
import com.zcf.pojo.Result;
import com.zcf.service.ArticleService;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.Pattern;
import org.apache.ibatis.annotations.Delete;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author zcf
 */
@RestController
@RequestMapping("/article")
public class ArticleController {
    @Resource
    private ArticleService articleService;

    @PostMapping
    public Result add(@RequestBody @Validated ArticleDto articleDto) {
        return articleService.add(articleDto);
    }


    @GetMapping
    public Result<PageBean<Article>> page(Integer pageNum, Integer pageSize, Integer categoryId, String state) {
        PageBean<Article> page = articleService.page(pageNum, pageSize, categoryId, state);
        return Result.success(page);
    }


    @GetMapping("/detail")
    public Result<Article> detail(Integer id){
       Article article= articleService.detail(id);
       return Result.success(article);
    }


    @PutMapping
    public  Result update(@RequestBody @Validated ArticleDto articleDto){
       articleService.update(articleDto);
       return Result.success();
    }


    @DeleteMapping
    public Result delete(String id){
      articleService.delete(id);
      return Result.success();
    }
}
